package com.chijun.mform.create.dialog;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;

import com.chijun.mform.R;
import com.chijun.mform.create.adapter.SelectFieldTypeAdapter;
import com.chijun.mform.create.field.Field;
import com.example.ccj.b.c.dialog.DialogBase;
import com.example.ccj.b.c.recycler.BaseRecycler;
import com.example.ccj.u.array.ArrayUtils;

import java.util.List;

/**
 * 展示字段类型列表dialog
 * 点击后返回
 */
public class SelectFieldDialog extends DialogBase {

    Field[] fields ;
    ISelectField iSelectField;
    public SelectFieldDialog(@NonNull Context context,Field[] fields,ISelectField iSelectField) {
        super(context);
        this.fields = fields;
        this.iSelectField = iSelectField;
    }

    @Override
    public void onInit() {
        isCanClose(true);
        setLayout(R.layout.dialog_form_select_field);
        setAlpha(1f);//透明度
        isCanClose(true);//点击允许关闭
        isShowBackground(false);//不显示背景
        setShowHeightRatio(true);//按比例显示
        setHeightRatio(0.5);//高度显示比例
        showInBottom();//底部弹出
        setFull(true);
        goneTitleLeftImage();

        setTitleCenterText("选择字段类型");

        List<Field> arrayList = ArrayUtils.asArrayList(fields);
        BaseRecycler<Field> fieldBaseRecycler = findViewById(R.id.dialog_form_select_field_rec);
        fieldBaseRecycler.setLayoutManager(new GridLayoutManager(this.getContext(),2));
        fieldBaseRecycler.setAdapter(arrayList,new SelectFieldTypeAdapter(arrayList, new ISelectField() {
            @Override
            public void complete(Field id) {
                if (iSelectField != null) iSelectField.complete(id);
                dismiss();
            }

            @Override
            public void cancel() {
                dismiss();
            }
        }));



    }

}
